package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxSpWzh;
import cn.stylefeng.guns.modular.lx.mapper.LxSpWzhMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxDdWzhParam;
import cn.stylefeng.guns.modular.lx.model.params.LxSpWzhParam;
import cn.stylefeng.guns.modular.lx.model.result.LxSpWzhResult;
import  cn.stylefeng.guns.modular.lx.service.LxSpWzhService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wzh
 * @since 2023-12-01
 */
@Service
public class LxSpWzhServiceImpl extends ServiceImpl<LxSpWzhMapper, LxSpWzh> implements LxSpWzhService {

    @Autowired
    private LxSpWzhMapper lxSpWzhMapper;
    @Override
    public void add(LxSpWzhParam param){
        LxSpWzh entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxSpWzhParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxSpWzhParam param){
        LxSpWzh oldEntity = getOldEntity(param);
        LxSpWzh newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxSpWzhResult findBySpec(LxSpWzhParam param){
        return null;
    }

    @Override
    public List<LxSpWzhResult> findListBySpec(LxSpWzhParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxSpWzhParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.lxSpWzhMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }


    private Serializable getKey(LxSpWzhParam param){
        return param.getSpId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxSpWzh getOldEntity(LxSpWzhParam param) {
        return this.getById(getKey(param));
    }

    private LxSpWzh getEntity(LxSpWzhParam param) {
        LxSpWzh entity = new LxSpWzh();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Override
    public void update2(LxDdWzhParam param) {
        lxSpWzhMapper.update2(param);
    }



}
